package com.springcloud.alibaba.controller;

import com.springcloud.alibaba.service.AccountService;
import com.springcloud.configclient.commons.entities.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
public class AccountController {

    @Autowired
    private AccountService service;
    @PostMapping(value = "/account/decrese")
    public CommonResult decreseAccount(@RequestParam("userId") long userId,
                                       @RequestParam("money") BigDecimal money){
        if(userId==0){
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println();
        System.out.println("------------------/account/decrese---------------------");
        System.out.println(userId);
        System.out.println(money);
        int result = service.decreseAccount(userId, money);
        return new CommonResult(222,"result",result);
    }

}
